package com.intelligent.ispc.utils;

/**
 * Created by Peter on 15/11/23.
 */
public enum LogUtil {

    INSERT(1, "Insert"),
    UPDATE(2, "Update"),
    DELETE(3, "Delete"),
    SUCCESS(4, "Success"),
    FAILURE(5, "Failure");

    private int index;
    private String code;

    LogUtil(int index, String code) {
        this.code = code;
        this.index = index;
    }

    public static LogUtil getValueOf(String code) {
        if (INSERT.getCode().equals(code)) {
            return INSERT;
        } else if (UPDATE.getCode().equals(code)) {
            return UPDATE;
        } else if (DELETE.getCode().equals(code)) {
            return DELETE;
        } else if (SUCCESS.getCode().equals(code)) {
            return SUCCESS;
        } else if (FAILURE.getCode().equals(code)) {
            return FAILURE;
        } else {
            return null;
        }
    }

    public static LogUtil getValueOf(int index) {
        switch (index) {
            case 1:
                return INSERT;
            case 2:
                return UPDATE;
            case 3:
                return DELETE;
            case 4:
                return SUCCESS;
            case 5:
                return FAILURE;
            default:
                return null;
        }
    }

    public String getCode() {
        return code;
    }

    public int getIndex() {
        return index;
    }
}
